//
//  DCEvaluateView.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/12/3.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCEvaluateView.h"
#import "DCEvaluateTableViewCell.h"
@interface DCEvaluateView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSArray *dataSource;
@property (nonatomic,strong) UITableView *tableView;
@end
@implementation DCEvaluateView

+(instancetype)creatTableViewWithFrame:(CGRect)frame dataSource:(NSArray *)dataSource {
    return [[self alloc]initWithFrame:frame dataSource:dataSource];
}
-(instancetype)initWithFrame:(CGRect)frame dataSource:(NSArray *)dataSource {
    if (self = [super init]) {
        self.frame = frame;
        self.dataSource = dataSource;
        [self addSubview:self.tableView];
    }
    return self;
}
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellStyleDefault;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = BackgroundColor;
    }
    return _tableView;
}
#pragma tableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DCEvaluateTableViewCell *cell = [DCEvaluateTableViewCell cellWithTableView:tableView];
    cell.model = self.dataSource[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [DCEvaluateTableViewCell getCellHeight];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
